<template>
  <div>
    <el-dialog :visible.sync='isShow' title='修改机构组' width="800px" @open="openDialogInit" @close="resetForm" :close-on-click-modal=false>
      <div v-loading="loading">
        <el-card>
          <el-form :model="formInline" ref="formInline" size="mini" :rules="rules" label-position="left" label-width="125px">
            <el-row :gutter="20">
               <el-col :span="12">
                <el-form-item label='应用编号' prop='appnum'>
                  <el-select v-model="formInline.appnum"  placeholder="请选择应用编号" disabled>
                    <el-option v-for="item in appQueryList" :key="item.AppNum" :label="item.AppNum + '-' + item.AppName" :value="item.AppNum">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="机构组编号:" prop="branchgroupnum">
                  <el-input v-model="formInline.branchgroupnum" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="机构组名称:" prop="branchgroupname">
                  <el-input v-model="formInline.branchgroupname" placeholder="请输入机构组名称"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="法人号:" prop="LegalPersonNum">
                  <el-input v-model="formInline.legalpersonnum" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人名称:" prop="LegalPersonName">
                  <el-input v-model="formInline.LegalPersonName" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
        <el-row style="margin:20px 0;text-align:right">
          <el-button size="mini" @click="closeDialog">取消</el-button>
          <el-button type="primary" size="mini" @click="modBranchGroup">确认</el-button>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import appQuery from "@/message/shared/appquery";
import request from "@/common/utils/request";
import branchGroup from "@/message/branchManage/branchGroupMgr/branch-group-mgr";
export default {
  props: { option: Object },
  data() {
    return {
      appQueryList: [],
      loading: false,
      formInline: {},
      rules: {
        branchgroupname: [
          { required: true, message: "请输入交易组名称", trigger: "blur" }
        ]
      }
    };
  },
  computed: {
    isShow: {
      get: function() {
        return this.option.isShow;
      },
      set: function(newValue) {
        this.option.isShow = newValue;
      }
    }
  },
  methods: {
      appQueryInit() {
      let resBody = new appQuery();
      resBody.data.UserNum = this.$store.getters.UserNum;
      request(resBody)
        .then(response => {
          this.appQueryList = response.RspInfo.Result;
        })
        .catch(error => {
          console.error("查询错误", error);
        });
    },
    // 打开窗口初始化
    openDialogInit() {
      this.appQueryInit();
      this.formInline = this.option.currentRow
      this.formInline.legalpersonnum = this.$store.getters.LegalPersonNum;
      this.formInline.LegalPersonName = this.$store.getters.LegalPersonName;
    },

    // 重置表单
    resetForm() {
      this.$refs["formInline"].resetFields();
    },

    /**
     * @desc 修改机构组
     */
    modBranchGroup() {
      this.$refs["formInline"].validate(valid => {
        if (valid) {
          this.loading = true;
          let resBody = new branchGroup();
          resBody.data.BranchGroupAppNum = this.formInline.appnum;
          resBody.data.BranchGroupNum = this.formInline.branchgroupnum;
          resBody.data.BranchGroupName = this.formInline.branchgroupname;
          resBody.data.LegalPersonNum = this.formInline.legalpersonnum;
          resBody.data.OperType = "M"; // 操作类型
          request(resBody)
            .then(response => {
              if (response.SYS_HEAD.ReturnCode === "000000") {
                this.loading = false;
                this.$message({
                  type: "success",
                  message: "机构组修改成功!"
                });
                this.isShow = false;
                this.$emit("refreshBrand");
              } else {
                this.loading = false;
                this.$message({
                  type: "error",
                  message: response.SYS_HEAD.ReturnMessage
                });
              }
            })
            .catch(error => {
              this.loading = false;
              console.log(error);
            });
        } else {
          this.$message({
            type: "warning",
            message: "必输项不能为空"
          });
          return false;
        }
      });
    },
    closeDialog(){
      this.isShow = false;
      this.$emit("refreshBrand");
    }
  }
};
</script>
<style lang="sass" scoped>

</style>
